package com.yufubao.api.controller.applet.product;

import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.constant.NotesConstant;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.dto.applet.product.SkuQueryPageDetailDto;
import com.yufubao.model.pojo.applet.product.SkuInfoEntity;
import com.yufubao.service.service.applet.product.SkuInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;





/**
 * sku信息
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-08-29 16:01:46
 */
@Api("sku信息")
@RestController
@RequestMapping("/applet/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 查询当前商户的sku信息
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    //@RequiresPermissions("gulimallproduct:skuinfo:list")
    @SystemLog(info = "查询当前商户的sku信息")
    @ApiOperation(value = "查询当前商户的sku信息", notes = NotesConstant.DEV)
    public ResponseResult queryPageDetail(@RequestBody @Valid SkuQueryPageDetailDto dto){
        PageUtils page = skuInfoService.queryPageDetail(dto);

        return ResponseResult.okResultPage("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{skuId}",method = RequestMethod.GET)
    @ApiOperation(value = "信息")
    @SystemLog(info = "sku信息信息")
    public ResponseResult info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return ResponseResult.okResultPage("SkuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存")
    @SystemLog(info = "sku信息保存")
    public ResponseResult save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "修改")
    @SystemLog(info = "sku信息修改")
    public ResponseResult update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除")
    @SystemLog(info = "sku信息删除")
    public ResponseResult delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return ResponseResult.ok();
    }

}
